package demo;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/30
 * Time: 14:30
 * Description:
 */
public class Test {

    public static void func(String s) {
        if(s == null){
            System.out.println("s == null");
            return;
        }

        if(s.length() == 0) {
            System.out.println("s是一个空的字符串");
        }
    }

    public String solve (String str) {
        // write code here
        if(str == null) return null;
        char[] chars = str.toCharArray();
        int i = 0;
        int j = chars.length-1;
        while(i < j) {
            char tmp = chars[i];
            chars[i] = chars[j];
            chars[j] = tmp;
            i++;
            j--;
        }

        return new String(chars);
    }

    public int firstNotRepeatingChar(String str) {
        if(str == null || str.length() == 0) {
            return -1;
        }

        int[] array = new int[128];//0
        for(int i = 0;i < str.length();i++) {
            char ch = str.charAt(i);
            array[ch]++;
        }

        for(int i = 0;i < str.length();i++) {
            char ch = str.charAt(i);
            if(array[ch] == 1) {
                return i;
            }
        }
        return -1;
    }
    public static void main14(String[] args) {
        String s = null;
        func(s);
        String s2 = "";
        func(s2);
    }

    public static void main13(String[] args) {
        String str = "Name=ZHangsan&Age=18";
        //System.out.println(str.toUpperCase());
        //System.out.println(str.toLowerCase());
        String ret = str.concat("gaobo");
        System.out.println(ret);
    }


    public static void main12(String[] args) {
        String str1 = "     ababcabc    dab   cde      ";
        System.out.println(str1);
        String ret = str1.trim();
        System.out.println(ret);
        //String ret = str1.substring(2,5);//截取2号位置，后面的所有元素
        //System.out.println(ret);
    }

    public static void main11(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] ss1 = str.split("&");
        for(String sx : ss1) {
            //System.out.println(sx);
            String[] ss2 = sx.split("=");
            for(String sx2 : ss2 ) {
                System.out.println(sx2);
            }
        }
    }

    public static void main10(String[] args) {
        String str1 = "Java30 12&21#hello";;
        //String[] strings = str1.split(" |&|#");
        String[] strings = str1.split("[ &#]");
        for(String s:strings) {
            System.out.println(s);
        }
    }

    public static void main9(String[] args) {
        String str1 = "192.168.1.1";
        String[] strings = str1.split("\\.");
        for(String s:strings) {
            System.out.println(s);
        }
    }

    public static void main8(String[] args) {
        String str1 = "hello#world#dasi#everyone";
        String[] strings = str1.split("#");
        for(String s:strings) {
            System.out.println(s);
        }
    }


    public static void main7(String[] args) {
        String str1 = "ababcabcdabcde";
        //String ret = str1.replace('a','p');
        //String ret = str1.replace("ab","ppp");
        //String ret = str1.replaceAll("ab","ppp");
        String ret = str1.replaceFirst("ab","ppp");
        System.out.println(ret);
    }

    public static int strLen(String s) {
        int index = s.lastIndexOf(" ");
        return s.length()-index-1;
    }

    public static void main6(String[] args) {
        String str = "abc abcd abcde abcdef";
        System.out.println(strLen(str));
    }


    public static void main5(String[] args) {
        String str1 = "ababcabcdabcde";
        //System.out.println(str1.startsWith("ab",1));
        System.out.println(str1.endsWith("de4"));
    }

    public static void main4(String[] args) {
        String str1 = "ababcabcdabcde";
        System.out.println(str1.lastIndexOf("abcd",8));
    }

    public static void main3(String[] args) {
        String str1 = "ababcabcdabcde";
        //System.out.println(str1.contains("abcdef"));
        System.out.println(str1.indexOf("abcd",6));//从头/fromindex到尾找到的第一个
    }

    public static void main2(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        //str1 和  str2
        System.out.println(str1.compareTo(str2));

    }
    public static void main1(String[] args) {
        String str1 = "Hello";
        String str2 = new String("hello");
        System.out.println(str1.equals(str2));//false
        System.out.println(str1.equalsIgnoreCase(str2));
        int a = 10;
        int b = 20;
        if(a > b) {
            System.out.println(a);
        }
    }
}
